package cn.kai.ums.controller;


import cn.kai.ums.mapper.UmsSpecialMapper;
import cn.kai.ums.model.UmsSpecial;
import cn.kai.ums.service.UmsSpecialService;
import cn.kai.ums.tools.JsonData;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("ums/v1/special")
@Api(tags = "专业控制类")
public class SpecialController {

    @Autowired
    private UmsSpecialMapper umsSpecialMapper;

    @Autowired
    private UmsSpecialService umsSpecialService;

    @ApiOperation("根据专业编号，专业名称，学院编号进行模糊查询")
    @GetMapping
    public JsonData getSpecialList(@RequestParam(defaultValue = "1",required = false) Integer pageNum
            ,@RequestParam(defaultValue = "5",required = false) Integer pageSize
            ,@RequestParam(defaultValue = "",value = "likespecial",required = false) String likespecial){

        Page<UmsSpecial> umsSpecialPage = umsSpecialMapper.selectPage(new Page<>(pageNum,pageSize)
                , Wrappers.<UmsSpecial>lambdaQuery()
                        .like(UmsSpecial::getSpecialNo,likespecial)
                        .or()
                        .like(UmsSpecial::getSpecialName,likespecial)
                        .or()
                        .like(UmsSpecial::getSpecialCollegeNo,likespecial));
        return JsonData.buildSuccess(umsSpecialPage);
    }

    @PostMapping
    public  JsonData saveSpecial(@RequestBody UmsSpecial umsSpecial){
        return JsonData.buildSuccess(umsSpecialService.save(umsSpecial));
    }

    @PutMapping
    public JsonData updateSpecial(@RequestBody UmsSpecial umsSpecial){
        return JsonData.buildSuccess(umsSpecialService.updateById(umsSpecial));
    }

    @DeleteMapping
    public JsonData delSpecial(@RequestParam Integer spid){

        return JsonData.buildSuccess(umsSpecialService.removeById(spid));
    }

    @PostMapping("/delBatchSpecial")
    public JsonData delBatchSpecial(@RequestBody List<Integer> spids){
        return JsonData.buildSuccess(umsSpecialService.removeByIds(spids));
    }

}
